package com.acwing.partition2;

import java.io.*;
import java.util.Arrays;
import java.util.BitSet;

/**
 * @author `RKC`
 * @date 2022/2/10 15:47
 */
public class AC164可达性统计 {

    private static final int N = 30010, M = 30010;
    private static int[] head = new int[N], ver = new int[M], next = new int[M], din = new int[N];
    private static int[] q = new int[N];
    //f[i]的二进制数表示节点i能访问到的点
    private static BitSet[] f = new BitSet[N];

    private static int n = 0, m = 0, qh = 0, qt = 0, idx = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        Arrays.fill(head, -1);
        for (int i = 0; i < m; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            add(a, b);
            din[b]++;
        }
        topsort();
        //反向做递推
        for (int i = n - 1; i >= 0; i--) {
            int u = q[i];
            f[u] = new BitSet(N);
            f[u].set(u, true);
            for (int j = head[u]; j != -1; j = next[j]) {
                f[u].or(f[ver[j]]);
            }
        }
        for (int i = 1; i <= n; i++) writer.write(f[i].cardinality() + "\n");
        writer.flush();
    }

    private static void topsort() {
        for (int i = 1; i <= n; i++) {
            if (din[i] == 0) q[qt++] = i;
        }
        while (qh != qt) {
            int u = q[qh++];
            for (int i = head[u]; i != -1; i = next[i]) {
                int v = ver[i];
                if (--din[v] == 0) q[qt++] = v;
            }
        }
    }

    private static void add(int a, int b) {
        ver[idx] = b;
        next[idx] = head[a];
        head[a] = idx++;
    }
}
